package entity

import (
	"gorm.io/gorm"
	v1 "inspector/pkg/meta/v1"
	"inspector/pkg/util/idutil"
)

type User struct {
	v1.ObjectMeta
	AtomGitId             string `gorm:"column:atom_git_id;"`
	InstallationId        string `gorm:"column:installation_id;"`
	AccessToken           string `gorm:"column:access_token;"`
	ExpiresIn             int64  `gorm:"column:expires_in;"`
	RefreshToken          string `gorm:"column:refresh_token;"`
	RefreshTokenExpiresIn int64  `gorm:"column:refresh_token_expires_in;"`
}

func (n *User) TableName() string {
	return "app_user"
}

// AfterCreate run after create database record.
func (n *User) AfterCreate(tx *gorm.DB) error {
	if n.InstanceID == "" {
		n.InstanceID = idutil.GetInstanceID("", 6)
	}
	return tx.Save(n).Error
}
